Introduction

 

PEB Trajectory Predictor stands for Physics-Engine-Based Trajectory Predictor. It invokes physics engine to simulate future frames and thus gives accurate prediction. It can predict bounces, it is compatible with air drag, angular drag, and physics materials.

PEB Trajectory Predictor is designed with performance in mind, with appropriate settings it can run smoothly on low-end devices.

 

Parameters

Here's the PEB Trajectory Predictor component:

PEB Trajectory Predictor Inspector

 

Explain

Line: The Line Renderer. If you use the prefab "PEB Trajectory Predictor.prefab" from "Blobcreate/Projectile Toolkit/Prefabs", it's been already set.

Simulatee: The Rigidbody to be simulated.

Obstacles: All the colliders to be simulated. If you have a bunch of GameObjects with collider on each of them that are grouped in one parent GameObject, make sure to drag each of them into the Obstacles field instead of the parent.

Update Obstacle Transforms: Turn this on for auto re-simulation, so that whenever any of the colliders moves, rotates, or scales, the prediction gets re-simulated.

Total Iterations: The total number of physics steps to simulate.

Max Iterations Every Frame: The max physics steps to simulate during one frame. This allocates physics simulation into several frames, thus optimizes the performance.

Simulation Timestep: The timestep of simulation. To get accurate prediction result, this should be the same as Fixed Timestep value in the project settings.

Launch Velocity: The launch velocity to be applied to the simulation.

Line Lerp Factor: Controls how smoothly the line is updated.

T Sync: Prevents the line from tearing (effective when Max Iterations Every Frame is smaller than Total Iterations).

 

Scripting Reference

The API of PEB Trajectory Predictor enables you to switch Simulatee and add/remove obstacles (colliders) during runtime.

 

Properties

 

LaunchVelocity

The launch velocity to be applied to the simulation.

 

UpdateObstacleTransforms

If you have any moving colliders, set this to true for auto re-simulation.

 

LineLerpFactor

Controls how smoothly the line is updated. The value should be in the range of 0f (exclusive) to 1f (inclusive). The smaller the value, the smoother the line updates.

 

TSync

Set to true to prevent the line from tearing (effective when Max Iterations Every Frame is smaller than Total Iterations).

 

Simulatee

The Rigidbody to be simulated.

 

Public Methods

 

SimulateAndRender

Tells the PEB Trajectory Predictor to do one round of simulation and render the line accordingly.

 

AddObstacle

Adds a collider to the simulation context.

 

RemoveObstacle

Removes a collider from the simulation context.